/**CopyRight[1990-2012]<lyc2877@gmail.com>
 */
#include "./include/Thread.h"
CThread::CThread()
{
  is_stop = false;
  is_already_stop = false;
  memset(m_cl_name, '\0', THREAD_NAME_LEN);
}

CThread::~CThread()
{
}

int32_t CThread::start_thread() {
  while(!is_stop){
    this->work();
  }
  is_already_stop = true;
  return 0;
}

int32_t CThread::stop_thread() {
  return 0;
}

int32_t CThread::print_time(char* in_szBuf) {
  struct timeval tt;
  gettimeofday(&tt, NULL);

  char szBuf[20] = {0};
  strftime(szBuf, 20, "%H:%M:%S", localtime(&tt.tv_sec));
  snprintf(in_szBuf, 30, "%s:%ld",
           szBuf,
           tt.tv_usec);
  return 0;
}

int32_t CThread::shutdown() {
  is_stop = true;
  while(!is_already_stop) {
    usleep(100);
  }
  printf("[%s]stoped!\n", m_cl_name);
  return 0;
}
